﻿using System;
using System.Security.Cryptography;
using System.Text;
using vite_core.Common.Extensions;


namespace vite_core.Common
{
    /// <summary>
    /// MD5加密方法
    /// </summary>
    public static class MD5Encryption 
    {
        public static string ToMD5(this string input)
        {
            using (MD5 md5 = MD5.Create())
            {
                byte[] inputBytes = Encoding.UTF8.GetBytes(input);
                byte[] hashBytes = md5.ComputeHash(inputBytes);

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < hashBytes.Length; i++)
                {
                    sb.Append(hashBytes[i].ToString("x2"));
                }

                return sb.ToString();
            }

        }
    }
}